package com.definity.toolkit.xml;

import java.io.InputStream;
import java.io.OutputStream;

import com.definity.toolkit.xml.converter.DynamicDomainConverter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XmlHelper {

	private final XStream xStream;
	
	public XmlHelper() {
		xStream = new XStream(new DomDriver());
		xStream.registerConverter(new DynamicDomainConverter());
	}
	
	public XmlHelper alias(String name, Class<?> type) {
		xStream.alias(name, type);
		return this;
	}
	
	public XmlHelper registerConverter(Converter converter) {
		xStream.registerConverter(converter);
		return this;
	}
	
	public Object fromXml(String xml) {
		return xStream.fromXML(xml);
	}

	public Object fromXml(InputStream stream) {
		return xStream.fromXML(stream);
	}
	
	public String toXml(Object obj) {
		return xStream.toXML(obj);
	}

	public void toXml(Object obj, OutputStream stream) {
		xStream.toXML(obj, stream);
	}
	
}
